// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import keyControl from "../keyControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class changePosition extends cc.Component {

    @property(cc.Node)
    targetPosition : cc.Node = null;

    onBeginContact(contact, self, other) {
        if(other.node.group == "role"){
            let pos = this.targetPosition.convertToWorldSpaceAR(cc.v2(0,0));
            let pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
            cc.tween(other.node).to(0,{
                position : pos2
            }).call(()=>{
                other.node.getComponent(cc.RigidBody).linearVelocity = cc.v2(0,-2000);
            }).start();
            keyControl.dropTable = false;

        }
    }
}
